package cc.android.testapp.ui.listbase;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.Arrays;

public abstract class BaseListView<D extends LineData, L extends BaseLine<D>> extends RecyclerView.Adapter<L> {

    protected final D[] mData;
    protected final int mLineLayout;

    public BaseListView(D[] pApps, int pLineLayout) {
        this.mData = pApps;
        this.mLineLayout = pLineLayout;

        Arrays.sort(mData);
    }

    @Override
    public L onCreateViewHolder(ViewGroup pParent, int pType) {
        View pLineV = LayoutInflater.from(pParent.getContext()).inflate(this.mLineLayout, pParent, false);
        return getNewLine(pLineV);
    }

    public abstract L getNewLine(View pLineV);

    @Override
    public void onBindViewHolder(L pLine, int pPos) {
        pLine.setData(this.mData[pPos]);
    }

    @Override
    public int getItemCount() {
        return this.mData.length;
    }
}
